rem @echo off

rem JH_CLSA.bat
rem Vaughan Johnson, March 2010
rem
rem Batch pre-processing for Johns Hopkins pulmonary 
rem recordings, using SoX on Microsoft Windows.
rem
rem See "Johns_Hopkins_CLSA_USAGE.txt" 
rem for usage instructions.
rem
rem Derived from sox-14.3.0 "batch-example.bat"
rem
rem This file should be in the same folder as sox.exe. 
rem You can then drag and drop a folder of audio files onto 
rem the batch file (or more typically, onto a shortcut of it on 
rem the desktop).
rem
rem The processed files end up in a folder with the same 
rem name as the original, but with "_processed" appended.


rem Change working directory to the one where this file exists, 
rem so we are in the same directory as sox.exe (and therefore 
rem do not need to add it to Windows PATH environment var).
rem Typically not necessary, but good to make sure. 
cd "%~dp0"


rem Make the new directory for transcoded files (from WMA to WAV). 
mkdir "%~1_wavs"

rem Use FFmpeg to transcode WMA files to WAV.
for %%A in ("%~1\*.wma") do (
   ffmpeg -i "%%A" "%~1_wavs\%%~nA.wav" 
)

rem Copy any WAV files, too. 
copy /Y "%~1\*.wav" "%~1_wavs\" 


rem Make the new directory for filtered files. 
mkdir "%~1_filtered"

rem Use SoX to bandpass filter and normalize to 0dB.
rem Note the output files will have the same names, 
rem just be in a different folder.
for %%A in ("%~1_wavs\*") do (
   sox --norm "%%A" "%~1_filtered\%%~nxA" bandpass 0.55 450
)


rem Open the folder with the processed files. 
explorer "%~1_filtered"


rem We're finished with the raw WAV files, so delete them.
rmdir /s /q "%~1_wavs"



pause
